package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.AddNursingProjectDto;
import com.zzyl.dto.GetPageNursingsDto;
import com.zzyl.dto.UpdateNursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;

import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingProjectServiceImpl implements NursingProjectService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> page(GetPageNursingsDto dto) {
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());

        Page<NursingProjectVo>  page = nursingProjectMapper.page(dto);

        return PageResponse.of(page,NursingProjectVo.class);
    }

    @Override
    public void insertNursingProject(AddNursingProjectDto dto) {

        nursingProjectMapper.insertNursingProject(dto);
    }

    @Override
    public NursingProject getNursingProjectById(Integer id) {
      return nursingProjectMapper.getNursingProjectById(id);
    }

    @Override
    public void updateNursingProjectById(UpdateNursingProjectDto dto) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(dto,nursingProject);
        nursingProjectMapper.updateNursingProjectById(nursingProject);
    }

    @Override
    public void deleteNursingProjectById(Integer id) {
    nursingProjectMapper.deleteNursingProjectById(id);
    }

    @Override
    public void status(Long id, Integer status) {
        NursingProject nursingProject = new NursingProject();
        nursingProject.setId(id);
        nursingProject.setStatus(status);
        nursingProjectMapper.updateNursingProjectById(nursingProject);
    }

    @Override
    public List<NursingProjectVo> getAllNursingProject() {
      return   nursingProjectMapper.getAllNursingProject();
    }
}

